﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <script src="/js/header.js"></script>
</head>
<body style="background-color: white;">
    <section class="container-fluid" style="background-color: white;">
        <form class="form-horizontal m15_t" id="form">
            <div class="tab-content">
                <div class="tab-pane fade in active" id="home">
                    <input type="hidden" name="bcid" value="0">
                    <div class="form-group paymentStart" id="divPaymentStart">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>付款区间起：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="paymentStart" maxlength="16" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group paymentEnd" id="divPaymentEnd">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>付款区间迄：</label>
                        <div class="">
                            <input class="form-control wd250" type="text" name="paymentEnd" maxlength="16" autocomplete="off">
                        </div>
                    </div>
                    <div class="form-group crossBankPay" id="divCrossBankPay">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>跨行转账：</label>
                        <select class="" name="crossBankPay">
                            <option value="1">同行</option>
                            <option value="2">跨行</option>
                            <option value="3">全部</option>
                        </select>
                    </div>
                    <div class="form-group depositType">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>存款等级：</label>
                        <div class="input-group wd250">
                            <input type="checkbox" name="deposit" value="A" />1x
                            <input type="checkbox" name="deposit" value="B" />2x
                            <input type="checkbox" name="deposit" value="C" />3x
                            <input type="checkbox" name="deposit" value="D" />4x
                            <input type="checkbox" name="deposit" value="E" />5x
                            <input type="checkbox" name="deposit" value="F" />6x
                            <input type="checkbox" name="deposit" value="G" />7x
                            <input type="checkbox" name="deposit" value="H" />8x
                            <input type="checkbox" name="deposit" value="I" />9x
                            <input type="checkbox" name="deposit" value="J" />10x
                            <input type="checkbox" name="deposit" value="K" />11x
                            <input type="checkbox" name="deposit" value="L" />12x
                            <input type="checkbox" name="deposit" value="X" />x
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label"><span class="WdateFmtErr">*</span>启用状态：</label>
                        <div class="wd250">
                            <label class="m10_r">
                                <input type="radio" name="enableStatus" value="1"> 启用
                            </label>
                            <label>
                                <input type="radio" name="enableStatus" value="2"> 禁用
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label">虚拟机编码：</label>
                        <div>
                            <input class="form-control wd250" type="text" name="vmClientId" maxlength="32" autocomplete="off" placeholder="虚拟机编码" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label">备注：</label>
                        <div class="input-group wd250">
                            <input class="form-control wd250" type="text" name="remark" maxlength="50" autocomplete="off">
                            <label id="lblRemark" class="m10_t"></label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="wd125 control-label">使用时间：</label>
                        <div class="input-group wd250">
                            <input class="form-control wd250" type="text" name="usingStatusRemark" maxlength="50" autocomplete="off">
                        </div>
                    </div>
                    
                </div>
            </div>
        </form>

    </section>

    <script type="text/javascript">

        var id = 0;

        $(function () {
            id = FlashPay.Util.GetQueryString("id");

            init(id);
        })

        function init(id) {

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Payment/GetPaymentCard?bcId=" + id,
                dataType: "json",
                contentType: "application/json",
                success: function (res) {
                    FlashPay.Util.SetInputVal("bcid", res.bcid);
                    $("input[name='enableStatus'][value=" + res.enableStatus+"]").attr("checked", true);

                    $("select[name='usbType']").find("option[value=" + res.usbType + "]").prop("selected", true);

                    FlashPay.Util.SetInputVal("paymentStart", res.paymentStart);
                    FlashPay.Util.SetInputVal("paymentEnd", res.paymentEnd);

                    $("select[name='crossBankPay']").find("option[value=" + res.crossBankPay + "]").prop("selected", true);
                    if (res.cardType == 3) {
                        var depositTypeArray = res.depositType.split(',');
                        for (var i = 0; i < depositTypeArray.length; i++) {
                            $('input[name="deposit"][value="' + depositTypeArray[i] + '"]').prop('checked', true);
                        }
                    }
                    FlashPay.Util.SetInputVal("remark", res.remark);
                    if (!FlashPay.Util.isNullOrEmptySpance(res.remarkPermission)) {
                        $("input[name='remark']").remove();
                        $("label#lblRemark").html(res.remark)
                    }
                    FlashPay.Util.SetInputVal("vmClientId", res.vmClientId);
                    FlashPay.Util.SetInputVal("usingStatusRemark", res.usingStatusRemark);
                    
                    cover.Remove();
                }
            });
        }

        function save() {

            var data = $("#form").serializeObject();

            var cover = FlashPay.UI.Mask({
                obj: $("body"),
                opacity: 0.5
            });

            depositType = [];

            $("input[name='deposit']:checked").each(function () {
                depositType.push($(this).val());
            });

            data.depositType = depositType.join(',');

            FlashPay.Util.Ajax({
                type: "POST",
                url: "/Payment/PaymentCardEdit",
                data: data,
                success: function (response) {
                    if (response.success) {
                        cover.Remove();
                        FlashPay.UI.DialogOpener().Tip_success("操作成功！");
                        FlashPay.UI.DialogOpener().doSearch();
                        FlashPay.UI.CloseDialog();
                    } else {
                        cover.Remove();
                        FlashPay.UI.Tip_short_warning("操作失败！" + response.errorMessage);
                    }
                },
                error: function (json) {
                    cover.Remove();
                    FlashPay.UI.Tip_warning("操作失败！请查看网络，请重试。");
                }
            });
        }

        $.fn.serializeObject = function () {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    </script>
</body>
</html>